package com.sh.xxj.rebot.app;

import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import com.hn.comm.Tools;
import com.sh.xxj.rebot.model.CourseModel;
import com.sh.xxj.rebot.model.CourseOptionModel;
import com.sh.xxj.rebot.model.TypeModel;
import com.sh.xxj.rebot.service.ConfigService;
import com.sh.xxj.rebot.service.CourseService;

public class FindLostVoice {
	public static void main(String[] args) throws Exception {

		// 通用配置
		Properties propCommon = new Properties();
		propCommon.load(new FileInputStream("res/config/common.properties"));
		ConfigService.COMMON_MENU_XML_PATH = propCommon
				.getProperty("COMMON_MENU_XML_PATH");

		// 语种的配置
		Properties propLanguage = new Properties();
		// 载入配置文件
		propLanguage.load(new FileInputStream("res/config/english.properties"));
		// 设置配置文件
		ConfigService.OUTPUT_PATH = propLanguage.getProperty("OUTPUT_PATH");
		ConfigService.FONT_PATH = propLanguage.getProperty("FONT_PATH");
		ConfigService.OUTPUT_MENU_XML_PATH = propLanguage
				.getProperty("OUTPUT_MENU_XML_PATH");
		ConfigService.TRANSLATE_API = propLanguage.getProperty("TRANSLATE_API");
		ConfigService.TRANSLATE_VOICE_API = propLanguage
				.getProperty("TRANSLATE_VOICE_API");
		ConfigService.TRANSLATE_VOICE_API_BACKUP = propLanguage
				.getProperty("TRANSLATE_VOICE_API_BACKUP");

		// ----------------------------------------------------------------------------------------------------------------------------------------------
		/**
		 * 生成课程服务_逻辑步骤 1. 读取XML模板中的数据并组织成JAVA对象 2. 将JAVA对象中的语言翻译成目标国家的语言 3.
		 * 下载目标国家的语音到目标文件夹 4. 生成语言对应的图片到目标文件夹 5. 将JAVA对象转换成XML到目标文件夹
		 */
		// 创建课件服务对象
		CourseService cs = new CourseService();
		System.out.println("1.	读取XML模板中的数据并组织成JAVA对象");
		// 1. 读取XML模板中的数据并组织成JAVA对象
		List<TypeModel> listTypeModel = cs
				.getTypeModeFromFilePath(ConfigService.COMMON_MENU_XML_PATH);

		int iTotalCards = 0;
		Map<String, String> mapExcel = new HashMap<String, String>();
		for (TypeModel tm : listTypeModel) {
			for (CourseModel cm : tm.getListCourseModel()) {
				for (CourseOptionModel com : cm.getListCourseOptionModel()) {
					if (!mapExcel.containsKey(com.getWord().toLowerCase()
							.trim())) {
						mapExcel.put(com.getWord().toLowerCase().trim(), com
								.getWord().toLowerCase().trim());
					}
					else
					{
						System.out.println("多余的单词:"+com.getWord());
					}
					// iTotalCards++;
				}
			}
		}
		System.out.println("iTotalCards=" + iTotalCards);

		File[] files = Tools
				.readAllFile("D:\\workspace_myeclipse10\\xxj_robot_web\\res\\data\\english\\course_stuff");
		Map<String, String> mapFile = new HashMap<String, String>();
		System.out.println("文件数量=" + files.length);
		System.out.println("文件比excel多的.");
		for (File file : files) {
			String name = file.getName()
					.substring(0, file.getName().lastIndexOf("."))
					.toLowerCase().trim();
			// System.out.println(name);
			if (!mapExcel.containsKey(name)) {
				System.out.println("Excel中缺少:" + name + ";realName="
						+ file.getName());
			}
			mapFile.put(name, name);
		}
		System.out.println("文件比excel多的.结束.................");

		for (Map.Entry<String, String> entry : mapExcel.entrySet()) {
			// System.out.println(entry.getKey() + ":" + entry.getValue()) ;
			if (!mapFile.containsKey(entry.getKey())) {
				System.out.println("文件中缺少:" + entry.getKey());
			}
		}
		System.out.println("Excel数量:" + mapExcel.size());

	}
}
